import {
  DataGrid,
  GridPagination,
} from '@mui/x-data-grid'
import { TablePagination } from './pagination'

const Table = (props) => {
  const {
    pagination = true,
    paginationProps,
    pageSize: defaultPageSize = 10,
    pageSizeOptions = [5, 10, 20, 50],
    ...rest
  } = props
  function CustomPagination(props) {
    return <GridPagination as={TablePagination} {...props} />
  }
  return <DataGrid
    hideFooter={!pagination}
    slots={{
      pagination: CustomPagination,
    }}
    slotProps={{
      pagination:{...paginationProps}
    }}
    pageSizeOptions={pageSizeOptions}
    initialState={{
      pagination: {
        paginationModel: {
          pageSize: pagination ? defaultPageSize : Number.MAX_VALUE ,
        },
      },
    }}
    {...rest}
  />
}
export default Table
